/*
    c++中的atoi()和stoi()函数
    都是把数字字符串转换成int输出
*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    //stoi & atoi
    cout<<" stoi & atoi examples:"<<endl;
    string s="123456";
    char a[]={'1','2','3','4'};
    cout<< stoi(s) << endl;  //stoi可以直接输出
    cout<< atoi(s.c_str()) << endl; //atoi对于string型的要用c_str()方法
    cout<< atoi(a) <<endl; //atoi对于char型的数组可以直接输出
    cout<<endl;

    //stol :将转换后的整数作为 long int 型
    cout<<" stol examples:"<<endl;
    string str1="1978520";
    long sstr1=stol(str1);
    cout<<str1<<" : "<<sstr1<<endl;
    cout<<endl;

    //stoul :将转换后的整数作为 无符号整数（unsigned long）
    cout<<" stoul examples:"<<endl;
    string str2="123456";
    unsigned long sstr2=stoul(str2);
    cout<<str2<<" : "<<sstr2<<endl;
    cout<<endl;

    //stoll :将字符串转换为 long long 型
    cout<<" stoll examples:"<<endl;
    string str3="854321699915";
    long long sstr3=stoll(str3);
    cout<<str3<<" : "<<sstr3<<endl;
    cout<<endl;

    //stoull :将字符串转化为 unsigned long long 型
    cout<<" stoull examples:"<<endl;
    string str4="564682335";
    unsigned long long sstr4=stoull(str4);
    cout<<str4<<" : "<<sstr4<<endl;
    cout<<endl;

    //stof :将字符串转换为 float 型
    cout<<" stof examples:"<<endl;
    string str5="25463.125";
    float sstr5=stof(str5);
    cout<<str5<<" : "<<sstr5<<endl;
    cout<<endl;

    //stold :将字符串转换为 long double 
    
}
